﻿#include "FITKAcousticsFEModel.h"
#include "FITKAcousticsDiscModel.h"
#include "FITKAbstractFESubSys.h"
#include "FITKAcousticsFEFace.h"
#include "FITKAcousticsSensors.h"
#include "FITKAcousticsFENodeMap.h"

#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractSection.h"

namespace Acoustics
{
    FITKAcousticsFEModel::FITKAcousticsFEModel()
    {
        //创建单元列表
        _elementList = new FITKAcousticsFESubSysElementList;
        //创建子系统管理器
        _subSysManager = new FITKAcousticsFESubSysManager;
        //创建面管理器
        _faceManager = new FITKAcousticsFEFaceManager;
        //创建传感器管理器
        _sensorManager = new FITKAcousticsSensorsManager;
        //创建节点映射器管理
        _nodesMapManager = new FITKAcousticsFENodeMapManager;
    }

    FITKAcousticsFEModel::~FITKAcousticsFEModel()
    {
        //销毁对象
        if (_elementList) delete _elementList;
        if (_subSysManager) delete _subSysManager;
        if (_faceManager) delete _faceManager;
        if (_sensorManager) delete _sensorManager;
        if (_nodesMapManager) delete _nodesMapManager;
    }

    FITKAcousticsFESubSysElementList* FITKAcousticsFEModel::getFESubSysElementList()
    {
        //获取单元列表
        return _elementList;
    }

    FITKAcousticsFESubSysManager* FITKAcousticsFEModel::getFESubSysManager()
    {
        //获取FE子系统管理器
        return _subSysManager;
    }

    FITKAcousticsFEFaceManager* FITKAcousticsFEModel::getFEFaceManager()
    {
        //获取FE面管理器
        return _faceManager;
    }

    FITKAcousticsSensorsManager* FITKAcousticsFEModel::getSensorManager()
    {
        //获取传感器管理器
        return _sensorManager;
    }

    FITKAcousticsFENodeMapManager* FITKAcousticsFEModel::getNodesMapManager()
    {
        //获取节点映射器管理
        return _nodesMapManager;
    }

    void FITKAcousticsFEModel::clearFEModel()
    {
        //清理FE子系统模型
        this->clear();
        if (_elementList) _elementList->removeAllElement();
        if (_subSysManager) _subSysManager->clear();
        if (_faceManager) _faceManager->clear();
        if (_sensorManager) _sensorManager->clear();
        if (_nodesMapManager) _nodesMapManager->clear();
    }

    void FITKAcousticsFESubSysElementList::setElementPropID(int elemID, int propID)
    {
        _elementPropHash.insert(elemID, propID);
    }

    int FITKAcousticsFESubSysElementList::getElementPropID(int elemID, bool* isFEProperty/* = nullptr*/)
    {
        if (!_elementPropHash.contains(elemID)) return -1;
        int propID = _elementPropHash.value(elemID);
        if (isFEProperty)
        {
            *isFEProperty = false;
            //获取离散数据
            Acoustics::FITKAcousticsDiscModel* discModel = FITKAPP->getGlobalData()->getMeshData<Acoustics::FITKAcousticsDiscModel>();
            if (!discModel) return propID;
            //FE模型
            Acoustics::FITKAcousticsFEModel* feModel = discModel->getFEModel();
            if (!feModel && feModel->getSectionManager()) return propID;
            if (feModel->getSectionManager()->getDataByID(propID))
                *isFEProperty = true;
        }
        return propID;
    }

    QString FITKAcousticsFESubSysElementList::getElementPropName(int elemID)
    {
        int propID = _elementPropHash.value(elemID);
        //获取材料名称
        Core::FITKAbstractNDataObject *obj = FITKDATAREPO->getTDataByID<Core::FITKAbstractNDataObject>(propID);
        if (!obj) return QString();
        return obj->getDataObjectName();
    }
}
